//
//  YLMonthlyBillHeaderCenterView.m
//  YLFinanceService
//
//  Created by she1323 on 2017/9/25.
//  Copyright © 2017年 she1323. All rights reserved.
//

#import "YLMonthlyBillHeaderCenterView.h"
#import <Masonry.h>
#import "YLGlobeHeader.h"
#import "WHDefaultNotificationCenter.h"
@interface YLMonthlyBillHeaderCenterView ()
@property (nonatomic, strong) UIImageView *refreshImage;

@property (nonatomic, weak) UILabel *leftLabel;

@property (nonatomic, weak) UILabel *rightLabel;

@end

@implementation YLMonthlyBillHeaderCenterView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setUpUI];
    }
    return self;
}

- (void)setUpUI
{
    __weak typeof(self) weakSelf = self;
    UILabel *leftLabel = [[UILabel alloc] init];
    _leftLabel = leftLabel;
    leftLabel.textColor = YLColor(60, 60, 60);
    leftLabel.font = [UIFont boldSystemFontOfSize:13.0f];
    [self addSubview:leftLabel];
    [leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf);
        make.left.mas_equalTo(weakSelf).mas_offset(15);
    }];
    
//    UIImageView *refreshImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Refresh"]];
//    [self addSubview:refreshImage];
//    _refreshImage = refreshImage;
//    [refreshImage mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.mas_equalTo(weakSelf).mas_offset(-15);
//        make.centerY.mas_equalTo(weakSelf);
//        make.width.height.mas_equalTo(18);
//    }];
    
//    UILabel *rightLabel = [[UILabel alloc] init];
//    _rightLabel = rightLabel;
//    rightLabel.font = [UIFont systemFontOfSize:13.0f];
//    rightLabel.textColor = YLGayColor;
//    [self addSubview:rightLabel];
//    [rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.mas_equalTo(refreshImage.mas_left).mas_offset(-10);
//        make.centerY.mas_equalTo(weakSelf);
//    }];
//
//    UIButton *refreshButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    [self addSubview:refreshButton];
//    [refreshButton mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(rightLabel);
//        make.right.mas_equalTo(weakSelf);
//        make.top.bottom.mas_equalTo(weakSelf);
//    }];
//
//    [refreshButton addTarget:self action:@selector(changeType:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)setType:(YLMonthlyBillHeaderCenterViewType)type
{
    _type = type;
    
    if (type == YLMonthlyBillHeaderCenterViewTypeHoldingAssets) {
        _leftLabel.text = @"持有资产";
        _rightLabel.text = @"切换预期收益";
    } else {
        _leftLabel.text = @"预期收益";
        _rightLabel.text = @"切换持有资产";
    }
    
    
}

// 切换类型
- (void)changeType:(UIButton *)sender
{
    sender.userInteractionEnabled = NO;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        sender.userInteractionEnabled = YES;
    });
    
    if (_type == YLMonthlyBillHeaderCenterViewTypeHoldingAssets) {
        [WHDefaultNotificationCenter wh_postEventToNotificationName:@"YLMonthlyChangeType" object:@(YLMonthlyBillHeaderCenterViewTypeExpectedReturn)];
    } else {
        [WHDefaultNotificationCenter wh_postEventToNotificationName:@"YLMonthlyChangeType" object:@(YLMonthlyBillHeaderCenterViewTypeHoldingAssets)];
    }
    
    
    
//    CABasicAnimation* rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
//    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
//    rotationAnimation.duration = 2;
//    rotationAnimation.cumulative = YES;
//    rotationAnimation.repeatCount = HUGE_VALF;
//    [_refreshImage.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}

- (void)stopAnimation
{
    [_refreshImage.layer removeAllAnimations];
}

@end
